package com.yfqy.admin.domain.mapper;

import com.yfqy.admin.domain.dto.revenue.DailyIncomeDTO;
import com.yfqy.admin.domain.dto.revenue.PaymentTypeStatsDTO;
import com.yfqy.admin.domain.dto.revenue.RevenueRecordDTO;
import com.yfqy.admin.domain.dto.revenue.RevenueRecordQuery;
import com.yfqy.admin.domain.entity.RevenueRecord;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

public interface RevenueRecordMapper {
    int deleteByPrimaryKey(Long id);

    int insert(RevenueRecord record);

    int insertSelective(RevenueRecord record);

    RevenueRecord selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RevenueRecord record);

    int updateByPrimaryKey(RevenueRecord record);

    void insertBranch(@Param("revenueRecords") List<RevenueRecord> revenueRecords);

    List<RevenueRecordDTO> selectPageListByConditions(@Param("query") RevenueRecordQuery query);

    RevenueRecord selectByCustomerName(@Param("customerName") String customerName);


    // 获取指定日期范围内的总收入
//    @Select("SELECT COALESCE(SUM(payment_amount), 0) FROM t_revenue_record WHERE record_time BETWEEN #{beginDate} AND #{endDate}")
    BigDecimal getTotalIncomeBetweenDates(@Param("beginDate") LocalDate beginDate,
                                          @Param("endDate") LocalDate endDate);

    // 获取指定日期的总收入
//    @Select("SELECT COALESCE(SUM(payment_amount), 0) FROM t_revenue_record WHERE record_time = #{date}")
    BigDecimal getIncomeByDate(@Param("date") LocalDate date);

    List<DailyIncomeDTO> getDailyIncomeBetweenDates(@Param("startDate") LocalDate startDate,
                                                    @Param("endDate") LocalDate endDate);


    /**
     * 优化后的支付类型统计（过去30天）
     */
    List<PaymentTypeStatsDTO> getOptimizedPaymentTypeStatsLast30Days();

    /**
     * 支持动态日期范围的统计
     */
    List<PaymentTypeStatsDTO> getOptimizedPaymentTypeStatsByDateRange(@Param("startDate") Date startDate,
                                                                      @Param("endDate") Date endDate);
}